//package com.lin.manager;
//
//import com.alibaba.fastjson2.JSON;
//import com.lin.manager.common.ex.BizException;
//import com.lin.manager.mq.entity.MqMessageeEntity;
//import com.lin.manager.mq.service.MqMessageService;
//import com.lin.manager.rabbitmq.RabbitMqCorrelationData;
//import com.lin.manager.rabbitmq.service.RabbitmqMessageRecordService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.ReturnedMessage;
//import org.springframework.amqp.rabbit.connection.CorrelationData;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
///**
// * @作者: 林江
// * @创建时间: 2024/4/14
// * @功能:
// */
//@Slf4j
//@Service
//public class RabbitmqMessageRecordServiceImpl implements RabbitmqMessageRecordService {
//    @Autowired
//    private MqMessageService mqMessageService;
//
//    @Override
//    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
//        log.info("确保notice消息可靠性投递到交换机，主键： {}", correlationData.getId());
//        MqMessageeEntity messagee = new MqMessageeEntity();
//        messagee.setStatus(ack ? 0 : 1);
//        messagee.setId(correlationData.getId());
//        messagee.setCause(cause);
//        if (correlationData instanceof RabbitMqCorrelationData) {
//            RabbitMqCorrelationData correlation = (RabbitMqCorrelationData) correlationData;
//            Object data = correlation.getData();
//            messagee.setContent(JSON.toJSONString(data));
//        }
//
//        if (!ack) {
//            BizException exception = new BizException(cause);
//            log.error("投递异常信息：{}", exception);
//        }
//
//        mqMessageService.save(messagee);
//    }
//
//    @Override
//    public void returns(ReturnedMessage returned) {
//        MqMessageeEntity messagee = new MqMessageeEntity();
//        messagee.setId(returned.getMessage().getMessageProperties().getCorrelationId());
//        messagee.setStatus(1);
//        messagee.setCause(returned.getReplyText());
//        mqMessageService.save(messagee);
//        log.error("notice消息无法投递到队列的原因：{}", returned.getReplyText());
//    }
//}
